package edu.nju.fs.action;

import org.apache.struts2.ServletActionContext;

import edu.nju.fs.dao.UserDao;
import edu.nju.fs.daoImpl.UserDaoImpl;
import edu.nju.fs.model.User;

public class RegisterAction {
	private String u_name;
	private String u_pass;
	private String message;
	private UserDao ud = new UserDaoImpl();
	
	public String execute(){
		User u=new User();
		u.setUsername(u_name);
		u.setPsw(u_pass);
		
		
		if (ud.save(u) != null) {
			message = "个人用户建立成功";
			ServletActionContext.getRequest().getSession()
					.setAttribute("type", "个人用户");
			ServletActionContext.getRequest().getSession()
					.setAttribute("user", u);
			return "success";
		} else {
			message = "用户名已存在";
			return "fail";
		}
	}
	
	public String getU_name() {
		return u_name;
	}

	public void setU_name(String u_name) {
		this.u_name = u_name;
	}

	public String getU_pass() {
		return u_pass;
	}

	public void setU_pass(String u_pass) {
		this.u_pass = u_pass;
	}

	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}
	
	
}
